package com.bauer.module.common.utils;

import com.bauer.module.common.error.ErrorCode;
import com.bauer.module.common.response.ApiResponse;
import com.bauer.module.common.response.TsResponse;

/**
 * @program: clock
 * @description:
 * @author: bauer weo
 * @create: 2019-09-16 21:23
 */
public class ApiResponseBuilder {


    public static <T> ApiResponse<T> newInstance(ErrorCode errorCode, T result) {
        return newInstance(errorCode.getCode(), errorCode.getMessage(), result);
    }

    public static <T> ApiResponse<T> newInstance(ErrorCode errorCode) {
        return newInstance(errorCode, null);
    }

    public static <T> ApiResponse<T> newInstance(TsResponse<T> response) {
        return newInstance(response.getCode(), response.getMessage(), response.getResult());
    }

    public static <T> ApiResponse<T> newInstance(String errorCode, String message) {
        return newInstance(errorCode, message, null);
    }

    public static <T> ApiResponse<T> newInstance(String errorCode, String message, T result) {
        ApiResponse<T> ApiResponse = new ApiResponse<>();
        ApiResponse.setMessage(message);
        ApiResponse.setCode(errorCode);
        ApiResponse.setResult(result);
        return ApiResponse;
    }
}
